

package com.hazelcast.internal.metrics.metricsets;

import com.hazelcast.internal.metrics.MetricDescriptor;
import com.hazelcast.internal.metrics.MetricsRegistry;

import java.io.File;

import static com.hazelcast.internal.metrics.MetricDescriptorConstants.*;
import static com.hazelcast.internal.metrics.ProbeLevel.MANDATORY;
import static com.hazelcast.internal.metrics.ProbeUnit.BYTES;
import static com.hazelcast.internal.util.Preconditions.checkNotNull;

/**
 * A MetricSet for files. Currently only displays space statistics for the partition of the user.home
 */
public final class FileMetricSet {

    private FileMetricSet() {
    }

    /**
     * Registers all the metrics in this metric pack.
     *
     * @param metricsRegistry the MetricsRegistry upon which the metrics are registered.
     */
    public static void register(MetricsRegistry metricsRegistry) {
        checkNotNull(metricsRegistry, "metricsRegistry");

        File file = new File(System.getProperty("user.home"));
        MetricDescriptor descriptor = metricsRegistry.newMetricDescriptor().withPrefix(FILE_PREFIX).withDiscriminator(FILE_DISCRIMINATOR_DIR, FILE_DISCRIMINATOR_VALUE_DIR);
        metricsRegistry.registerStaticProbe(file, descriptor, FILE_METRIC_FREESPACE, MANDATORY, BYTES, File::getFreeSpace);
        metricsRegistry.registerStaticProbe(file, descriptor, FILE_METRIC_TOTALSPACE, MANDATORY, BYTES, File::getTotalSpace);
        metricsRegistry.registerStaticProbe(file, descriptor, FILE_METRIC_USABLESPACE, MANDATORY, BYTES, File::getUsableSpace);
    }
}
